
if(sessionStorage.getItem("name")){
	//alert(localStorage.getItem("name"));
	$('#name').text(sessionStorage.getItem("name"));
	//sendData.planuserid =sessionStorage.getItem("userId");
//	setthenum();
	onload();
}else{
	var _config ;
	$.ajax({
		type : "post",
		data:JSON.stringify({"pageUrl":location.href.replace(/\\&/g,'%26')}),
		contentType: "application/json; charset=utf-8",
		async: false,
		url : "../dingding/getconfig",
		dataType : "json",
		success : function(suc) {
			_config = suc.config;
		}
	}); 
	dd.ready(function() {
		//channel runtime  requestOperateAuthCode requestAuthCode
	    dd.runtime.permission.requestAuthCode({
	        corpId: _config.corpId,
	        onSuccess: function(result) {
	        	getuserId(result);
	        },
	        onFail : function(err) {
	        	alert("错误"+JSON.stringify(err))
	        }
	 
	    });
	});
	function getuserId(result){
			    //$("body").text('https://oapi.dingtalk.com/user/getuserinfo?code=' + result.code + '&access_token='+ _config.token);
		$.ajax({
			url : '../dingding/dd',
			type : 'POST',
			data:JSON.stringify({"code":result.code,"token":_config.token}),
			contentType: "application/json; charset=utf-8",
			dataType : "json",
			success : function(suc) {
			    if(suc.status == '1002'){
			    	sessionStorage.setItem("userId",suc.userJson.userid);
			    	sessionStorage.setItem("name",suc.userJson.name);
			    	sessionStorage.setItem("jobnumber",suc.userJson.jobnumber);
			    	sessionStorage.setItem("deptId",suc.userJson.department);
					$('#name').text(sessionStorage.getItem("name"));
			    	onload();
			    }else{
			    	alert(suc.msg);
			    }

			},
			error : function(xhr, errorType, error) {
					alert(errorType + ', ' + error);
				}
		});
	}
	dd.error(function(err) {
		alert('dd error: ' + JSON.stringify(err));
	});
}


function onload(){
	addClick();
}
function addClick(){
	$('.bb_img').on('click',function(){
		window.location.href=$(this).attr('pageUrl');
	});
}
/*function setthenum(){
	$.ajax({              //待办事项
	url: "../../unite_platform/work_plan_info/getBody"
	,type:'post'
	,async: false
	,contentType: "application/json; charset=utf-8"
	,data:JSON.stringify(sendData) 
	,dataType:'json'
	,success: function(res){
		console.log(res.data);
		for(var p in res.data){//遍历json对象的每个key/value对,p为key
 		    var  shuzu = res.data[p];
				for(var p1 in shuzu){
					var thelength = shuzu[p1].length;
					var theshuzu = shuzu[p1];
							for(var a1=0;a1<thelength;a1++){
								resdata.push(theshuzu[a1]);
							}
 				}
		}
		thesum=resdata.length;
		$('#add_number').html(thesum);
	}
	});
}*/
